import { defineStore } from 'pinia'
import type { User } from '@/types/user'
import { ref } from 'vue'
export const useUserStore = defineStore(
  'cp-user',
  () => {
    // 用户信息
    const user = ref<User>()
    // 设置用户信息
    const setUser = (data: User): void => {
      user.value = data
    }

    // 清空用户数据
    const delUser = (): void => {
      user.value = undefined
    }

    // 记录回跳地址
    const returnUrl = ref('')
    const setReturnUrl = (url: string) => (returnUrl.value = url)
    const delUrl = () => (returnUrl.value = '')
    return { user, setUser, delUser, returnUrl, setReturnUrl, delUrl }
  },
  {
    // 开启数据持久化
    persist: true
  }
)
